package Servlet;

import Damain.emp;
import Service.EmpService;
import Service.EmpServiceImpl;
import Utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 *分页查询
 */
@WebServlet(name = "EmpListServlet", urlPatterns = "/empListServlet")
public class EmpListServlet extends HttpServlet {
    private EmpService empService = new EmpServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收到页面传入的参数  没有传入默认为第一页
        String SpageCode = request.getParameter("pageCode");
        //默认第一页
        int PageCode = 1;
        //当前页显示多少条数据
        int PageSize = 10;
        //判断值不为空并且 不为空格
        if (SpageCode!=null && !SpageCode.trim().isEmpty()){
            //把pagecode 转换为整形
            PageCode = Integer.parseInt(SpageCode);
        }

        Page<emp> page = empService.selEmpPage(PageCode,PageSize);
request.setAttribute("page",page);
//请求转发
        request.getRequestDispatcher("/pages/emplist.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
